home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / graphics / gnuplot / term / cgi.trm < prev    next >
Text File  |  1993-09-15  |  4KB  |  233 lines

  1. /*
  2.  * $Id: cgi.trm%v 3.50 1993/07/09 05:35:24 woo Exp $
  3.  *
  4.  */
  5.  
  6. /* GNUPLOT - cgi.trm */
  7. /*
  8.  * Copyright (C) 1990 - 1993 Ronald Florence
  9.  *
  10.  * Permission is hereby granted for unlimited non-commercial
  11.  * use of this code, on condition that the copyright
  12.  * notices are left intact and any modifications to the source
  13.  * code are noted as such.  No warranty of any kind is implied
  14.  * or granted for this material.
  15.  *
  16.  * This file is included by ../term.c.
  17.  *
  18.  * This terminal driver supports SCO CGI drivers
  19.  *
  20.  * AUTHOR
  21.  *   Ronald Florence <ron@mlfarm.com>
  22.  */
  23.  
  24. #ifdef VGA_MONO
  25. static short rgb[16][3] = {
  26.   0,    0,      0,      /* Black        */
  27.   1000,    1000,    1000,    /* White    */
  28.   800,    800,    0,    /* Red        */
  29.   0,    600,    0,    /* Green    */
  30.   0,    800,    800,    /* Blue        */
  31.   1000,    1000,    400,    /* Yellow    */
  32.   0,    600,    600,    /* Cyan        */
  33.   600,    600,    600,    /* Magenta    */
  34.   800,    800,    0,    /* Brown    */
  35.   600,    600,    600,    /* Lt. Grey    */
  36.   400,    600,    400,    /* Dark Grey    */
  37.   400,    600,    1000,    /* Lt. Blue    */
  38.   400,    1000,    400,    /* Lt Green    */
  39.   400,    1000,    1000,    /* Lt Cyan    */
  40.   1000,    600,    400,    /* Lt Red    */
  41.   600,    600,    1000    /* Lt Magenta    */
  42. };
  43. #endif
  44.  
  45. #define CGI_XMAX    32767
  46. #define CGI_YMAX    32767
  47. #define CGI_VTIC    (CGI_YMAX / 75)
  48. #define CGI_HTIC    term_tbl[term].h_tic
  49. #define CGI_VCHAR    term_tbl[term].v_char
  50. #define CGI_HCHAR    term_tbl[term].h_char
  51. #define CRT        (gout[45] == 0)
  52. #define CGICOLORS    gout[13]
  53. #define CGILINES    gout[6]
  54. #define CGIROTATES    gout[36]
  55. #define CGITEXTALIGN    gout[48]
  56.  
  57. static short gout[66];
  58. static short cgidev;
  59. static short vect[4];
  60. static short gin[19] = {
  61.  0,    /* default aspect ratio */
  62.  1,    /* solid line */
  63.  1,    /* line color */
  64.  1,    /* marker type . */
  65.  1,    /* marker color */
  66.  1,    /* graphics text font */
  67.  1,    /* graphics text color */
  68.  0,    /* fill interior style */
  69.  0,    /* fill style index */
  70.  1,    /* fill color index */
  71.  1     /* prompt for paper changes */
  72.  };
  73.  
  74. char    *cgidriver, *getenv();
  75.  
  76.  
  77. CGI_init()
  78. {
  79.   if (getenv(cgidriver = "CGIDISP") == NULL)
  80.     HCGI_init();
  81. }
  82.  
  83.  
  84. HCGI_init()
  85. {
  86.   if (getenv(cgidriver = "CGIPRNT") == NULL)
  87.     int_error("no CGI driver", NO_CARET);
  88. }
  89.  
  90.  
  91. CGI_graphics()
  92. {
  93.   int    i, aspect;
  94.   char *s;
  95.   short font_cap[9];
  96.   char    err_str[80];
  97.  
  98.   if ( (s=getenv("ASPECT")) != NULL && (aspect=atoi(s)) >= 0 && aspect <= 3 )
  99.     gin[0] = aspect;
  100.   for (i = 0; cgidriver[i]; i++) 
  101.     gin[11+i] = cgidriver[i];
  102.   gin[18] = ' ';
  103.  
  104.   if (v_opnwk(gin, &cgidev, gout) < 0) 
  105.     {
  106.       sprintf(err_str, "CGI error %d opening %s", -vq_error(), cgidriver);
  107.       int_error(err_str, NO_CARET);
  108.     }
  109.   vqt_representation(cgidev, 9, font_cap);
  110.   CGI_VCHAR = font_cap[8] * 3 / 2;
  111.   CGI_HCHAR = font_cap[7];
  112.   CGI_HTIC = CGI_VTIC * ((double) gout[1] / (double) gout[4]) / 
  113.             ((double) gout[0] / (double) gout[3]);
  114. #ifdef VGA_MONO
  115.   if (CGICOLORS > 2)
  116.     vsc_table(cgidev, 0, CGICOLORS, rgb);
  117. #endif
  118. }
  119.  
  120.  
  121. CGI_text()
  122. {
  123.   if (CRT)  
  124.     {
  125.       short ptin[2];
  126.       char  strin[2];
  127.       
  128.       ptin[0] = 0;
  129.       ptin[1] = 0;
  130.       vrq_string(cgidev, 1, 0, ptin, strin);
  131.     }
  132.   v_clswk(cgidev);
  133. }
  134.  
  135.  
  136. CGI_reset()
  137. {
  138. }
  139.  
  140.  
  141. CGI_move(x, y)
  142.      int x, y;
  143. {
  144.   vect[0] = x;
  145.   vect[1] = y;
  146. }
  147.  
  148. CGI_vector(x, y)
  149.      int x, y;
  150. {
  151.   vect[2] = x;
  152.   vect[3] = y;
  153.   v_pline(cgidev, 2, vect);
  154.   vect[0] = x;
  155.   vect[1] = y;
  156. }
  157.  
  158.  
  159. CGI_linetype(linetype)
  160.      int linetype;
  161. {
  162.   short lcolor;
  163.  
  164.   if (CGICOLORS > 2) 
  165.     {
  166.       lcolor = (linetype + 2) % CGICOLORS + 1;
  167.       vsl_color(cgidev, lcolor);
  168.       vsm_color(cgidev, lcolor);
  169.     }
  170.   vsl_type(cgidev, (linetype < 1) ? 1 : (linetype % CGILINES) + 1);
  171. }
  172.  
  173.  
  174. CGI_put_text(x, y, str)
  175. int x, y;
  176. char *str;
  177. {
  178.   v_gtext(cgidev, (short) x, (short) y, str);
  179. }
  180.  
  181.  
  182. CGI_text_angle(ang)
  183. int    ang;
  184. {
  185.   if (!CGIROTATES)
  186.     return FALSE;
  187.                 /* angles are 1/10 degree ccw */
  188.   vst_rotation(cgidev, (ang) ? 900 : 0);
  189.   return TRUE;
  190. }
  191.  
  192.  
  193. CGI_justify_text(mode)
  194. enum JUSTIFY mode;
  195. {
  196.   short hor_in, hor_out, vert_out;
  197.  
  198.   if (!CGITEXTALIGN)
  199.     return FALSE;
  200.  
  201.   switch (mode)
  202.     {
  203.     case LEFT:   hor_in = 0; break;
  204.     case CENTRE: hor_in = 1; break;
  205.     case RIGHT:  hor_in = 2; break;
  206.     }
  207.   vst_alignment(cgidev, hor_in, 1, &hor_out, &vert_out); 
  208.   return TRUE;
  209. }
  210.  
  211.  
  212. #define POINT_TYPES 6
  213.  
  214. CGI_point(x,y,num)
  215.      int x, y, num;
  216. {
  217.   short  point[2];
  218.   static short cgimarker[POINT_TYPES] = {1, 2, 6, 4, 5, 3};
  219.                           /* .  +  <> [] X  * */
  220.   if (num < 0)
  221.     {
  222.       CGI_move(x, y);
  223.       CGI_vector(x, y);
  224.     }
  225.   else
  226.     {
  227.       vsm_type(cgidev, cgimarker[num % POINT_TYPES]);
  228.       point[0] = x;
  229.       point[1] = y;
  230.       v_pmarker(cgidev, 1, point);
  231.     }
  232. }
  233.